package com.gly091020.client;

import com.gly091020.MathDragonFun;
import com.gly091020.NetWorkingPackId;
import com.gly091020.client.screen.MathScreen;
import me.shedaniel.autoconfig.ConfigData;
import me.shedaniel.autoconfig.event.ConfigSerializeEvent;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;

public class MathDragonClient implements ClientModInitializer {

    @Override
    public void onInitializeClient() {
        ClientPlayNetworking.registerGlobalReceiver(NetWorkingPackId.ToPlayer,
                (minecraftClient, clientPlayNetworkHandler, packetByteBuf, packetSender) -> {
            Integer id = packetByteBuf.readInt();
            float amount = packetByteBuf.readFloat();
            if (minecraftClient.player != null) {
                minecraftClient.execute(() -> {
                    MathScreen.open(MathDragonFun.getRandomMathematical(), id, amount);
                });
            }else{
                throw new RuntimeException("游戏没进存档呢你发什么数据包？？？");
            }
        });
    }
}
